﻿using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Xml;

namespace T.FAS.Runtime.DataAccess.SQLDom
{
    /// <summary>
    /// 子查询关联项
    /// </summary>
    /// <remarks>子查询关联项</remarks>
    [Serializable]
    public class SubQueryConditionItem : SqlElement
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public SubQueryConditionItem()
        {
            SubQueryField = new ConditionField();
            OuterQueryField = new ConditionField();
        }

        /// <summary>
        /// 左连接主表的条件中的对应字段
        /// </summary>
        public ConditionField SubQueryField { get; set; }

        /// <summary>
        /// 左连接的表的条件对应字段
        /// </summary>
        public ConditionField OuterQueryField { get; set; }

        /// <summary>
        /// 转换成SQL
        /// </summary>
        /// <returns>SQL</returns>
        public override string ToSQL()
        {
            return string.Format("{0}={1}", SubQueryField.ToSQL(), OuterQueryField.ToSQL());
        }

        /// <summary>
        /// 克隆
        /// </summary>
        /// <returns>关联条件项</returns>
        public override object Clone()
        {
            SubQueryConditionItem newValue = base.Clone() as SubQueryConditionItem;

            if (SubQueryField != null)
                newValue.SubQueryField = SubQueryField.Clone() as ConditionField;
            if (OuterQueryField != null)
                newValue.OuterQueryField = OuterQueryField.Clone() as ConditionField;

            return newValue;
        }
    }
}